package rdd.transform

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.rdd.RDD

object Spark02_RDD_Operator_Transform {
  def main(args: Array[String]): Unit = {
    val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc = new SparkContext(sparkConf)
    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4), 2)
    //把一个分区的数据全部拿到后再操作，map是把分区内的数据来一条操作一条
    val mapRDD: RDD[Int] = rdd.mapPartitions(
      iter => {
        println(">>>>>>>>>>>>>>>>>")
        iter.map(_ * 2)
      }
    )
    mapRDD.collect().foreach(println)
    sc.stop()
  }
}
